Import cal3d

Class CalMesh

	Field m_model:CalModel
	Field m_coreMesh:CalCoreMesh
	Field m_vectorSubmesh:CalSubmesh[]


	Method New()

		m_model = Null
		m_coreMesh = Null
		m_vectorSubmesh = New CalSubmesh[0]
	
	End
	
	Method New(coreMesh:CalCoreMesh)
	
		m_model = Null
		m_coreMesh = coreMesh
		m_vectorSubmesh = New CalSubmesh[0]
		
		
		Local vectorCoreSubmesh:CalCoreSubmesh[] = coreMesh.getVectorCoreSubmesh()
		Local submeshCount:Int = vectorCoreSubmesh.Length
		
		For Local submeshId:Int = 0 To submeshCount-1
			m_vectorSubmesh = m_vectorSubmesh.Resize(m_vectorSubmesh.Length+1)'push(New Cal3D.CalSubmesh(vectorCoreSubmesh[submeshId]))
			m_vectorSubmesh[m_vectorSubmesh.Length-1] = New CalSubmesh(vectorCoreSubmesh[submeshId])
		Next		
	End
	
	Method getCoreMesh:CalCoreMesh()
		Return m_coreMesh
	End


	Method getSubmesh:CalSubmesh(submeshId:Int)
		If submeshId < 0 Or submeshId >= m_vectorSubmesh.Length then
			Print "Invalid Submesh ID"
			Return Null
		Endif
	
		return m_vectorSubmesh[submeshId]	
	
	End
	
	Method getSubmeshCount:Int()
		Return m_vectorSubmesh.Length
	End
	
	Method getVectorSubmesh:CalSubmesh[]()
		Return m_vectorSubmesh
	End
	
	Method setLodLevel:Void(lodLevel:Float)
		For Local submeshId:Int = 0 To m_vectorSubmesh.Length-1
			' set the lod level in the submesh
			m_vectorSubmesh[submeshId].setLodLevel(lodLevel)
		Next		
	End
	
	Method setMaterialSet:Void(setId:Int)
		For Local submeshId:Int = 0 To m_vectorSubmesh.Length
			' get the core material thread id of the submesh
			Local coreMaterialThreadId:Int = m_vectorSubmesh[submeshId].getCoreSubmesh().getCoreMaterialThreadId()
	
			' get the core material id for the given set id in the material thread
			Local coreMaterialId:Int = m_model.getCoreModel().getCoreMaterialId(coreMaterialThreadId, setId)
	
			' set the new core material id in the submesh
			m_vectorSubmesh[submeshId].setCoreMaterialId(coreMaterialId)
		Next		
	End
	
	Method setModel:Void(model:CalModel)
		m_model = model
	End
	
	Method disableInternalData:Void()
		For Local submeshId:Int = 0 To m_vectorSubmesh.Length
			' disable internal data of the submesh
			m_vectorSubmesh[submeshId].disableInternalData()
		Next		
	End

End Class